package com.zmall.cart.listener;

import com.zmall.cart.service.ICartService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
@RequiredArgsConstructor
public class TradeStatusListener {

    private final ICartService cartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "trade.cart.success.queue", durable = "true"),
            exchange = @Exchange(name = "cart.direct"),
            key = "trade.success"
    ))
    public void listenTradeSuccess(Set<Long> ids) {
        cartService.removeByItemIds(ids);
    }
}